#ifndef ITEM_H
#define ITEM_H


#include "models_global.h"
#include "AbstractItem.h"


#include <QSharedData>
#include <QSharedDataPointer>



class MODELSSHARED_EXPORT ValueItem : public AbstractItem
{
    Q_OBJECT

    class Data : public QSharedData
    {
    public:
        Data() {}
        Data(const Data& other) : QSharedData(other)
        {
            value = other.value;
        }

        QVariant value;
    };


public:

    enum DataType
    {
        DataType_FIRST = AbstractItem::DataType_LAST + 1,

        ValueData = DataType_FIRST,

        DataType_LAST = ValueData
    };


    Q_INVOKABLE ValueItem(AbstractItem* parent = 0);
    Q_INVOKABLE ValueItem(const QString& name, AbstractItem* parent = 0);
    ValueItem(const ValueItem& other);



    virtual int fieldCount() const;
    virtual QString fieldName(const int &field) const;
    virtual int field(const QString &field_name) const;

    QVariant value() const;
    void setValue(const QVariant& value);

    void addReference(ValueItem* otherItem);
    QList<ValueItem*> references() const;


protected:

    virtual void setCustomData(const int &field, const QVariant &data);
    virtual QVariant customData(const int &field, int role = Qt::DisplayRole) const;


private:

    QSharedDataPointer<Data> d;

    friend class ValueItem;

};


typedef QList<ValueItem*> ValueItemList;

Q_DECLARE_METATYPE(ValueItem*);


#endif // ITEM_H
